package com.lzz.bottomencapsulation.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

/**
 * Created by apple on 2017/12/21.
 */

public class TimeUtil {

    /**
     * 获取时间戳   时分秒
     *
     * @param time
     * @return
     */
    public static String getProgressTextHms(long time) {
        time = time - TimeZone.getDefault().getRawOffset();
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        SimpleDateFormat h = new SimpleDateFormat("HH");
        if (h.format(calendar.getTime()).equals("00")) {
            return getProgressTextms(time);
        }
        SimpleDateFormat fmat = new SimpleDateFormat("HH:mm:ss");
        return fmat.format(calendar.getTime());
    }

    /**
     * 获取时间戳   时分
     *
     * @param time
     * @return
     */
    public static String getProgressTextms(long time) {
        time = time - TimeZone.getDefault().getRawOffset();
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        SimpleDateFormat fmat = new SimpleDateFormat("mm:ss");
        return fmat.format(calendar.getTime());
    }

    /**
     * 获取时间戳   根据时长获取时分秒
     *
     * @param time
     * @return
     */
    public static String getProgressText(long time) {
        if (time >= 3600) return getProgressTextHms(time);
        else return getProgressTextms(time);
    }
}
